#include "clientconmanager.h"
ClientConManager* ClientConManager::_instance = NULL;

ClientConManager::ClientConManager(QObject *parent) :
    QObject(parent)
{
}
ClientConManager* ClientConManager::getInstance()
{
    if(_instance == NULL)
        _instance = new ClientConManager();
    return _instance;
}


bool ClientConManager::connectToServer(QString cStrIp, int iPort)
{
    //create new server connection
    ClientServer* server = new ClientServer();
    m_aServers.push_back(server);
    //synchronous connection
    return server->connectToServer(cStrIp, iPort);
}

bool ClientConManager::disconnectFromAllServers()
{
    //
    bool bSuccess = true;
    for(int i = 0; i < m_aServers.size(); i++) {
        if( m_aServers[i]->disconnectFromServer() == false )
            bSuccess = false;
    }
    return bSuccess;
}


bool ClientConManager::reconnectAllServers()
{
    bool bSuccess = true;
    for(int i = 0; i < m_aServers.size(); i++) {
       if( m_aServers[i]->reconnect() == false )
           bSuccess = false;
    }
    return bSuccess;
}

bool ClientConManager::clearAllServers()
{
    disconnectFromAllServers();
    for(int i = 0; i < m_aServers.size(); i++) {
        delete m_aServers[i];
    }
    m_aServers.clear();
    return true;
}
